import axios from "axios"
import { getEncodeHeader } from "./tool/index.js"
import { APP_KEY, APP_SECRET } from "./secret.js"

// axios 拦截器
const api = axios.create({
  baseURL: "https://live-open.biliapi.com"
})

// 鉴权加密处理headers，下次请求自动带上
api.interceptors.request.use(config => {
  const headers = getEncodeHeader(
    config.data,
    APP_KEY,
    APP_SECRET
  )
  config.headers.concat(headers)
  return config
})

export default api
